package org.cms.nio;

import java.io.IOException;

import org.cms.nio.bufferpool.SharedBufferPool;


/**
 * @Description: 
 * @Department:
 * @author andy.lhc
 * @date 2016年6月2日 上午10:05:14 
 */
public class NIOReactorPool {
  private final NIOReactor[] reactors;
  private volatile int nextReactor;

  public NIOReactorPool(String name, int poolSize, SharedBufferPool shearedBufferPool) throws IOException {
      reactors = new NIOReactor[poolSize];
      for (int i = 0; i < poolSize; i++) {
          NIOReactor reactor = new NIOReactor(name + "-" + i, shearedBufferPool);
          reactors[i] = reactor;
          reactor.startup();
      }
  }

  public NIOReactor getNextReactor() {
      int i = ++nextReactor;
      if (i >= reactors.length) {
          i = nextReactor = 0;
      }
      return reactors[i];
  }
}

